package com.example.dmcommom.Enum;

import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yym
 */

@Getter
public enum ElectricityCategoryEnum {
	uni_tariff(0, "单一制"),
	two_part_tariff(1, "两部制"),
	no_diff(2, "单一制&两部制");

	private final int code;
	private final String name;

	ElectricityCategoryEnum(int code, String name) {
		this.code = code;
		this.name = name;
	}

	public static ElectricityCategoryEnum fromString(String text) {
		for (ElectricityCategoryEnum e : ElectricityCategoryEnum.values()) {
			if (e.getName().equals(text)) {
				return e;
			}
		}
		return no_diff;
	}

	public static ElectricityCategoryEnum fromCode(Integer integer) {
		for (ElectricityCategoryEnum e : ElectricityCategoryEnum.values()) {
			if (e.getCode() == integer) {
				return e;
			}
		}
		return no_diff;
	}

	public static String fromCodeGetName(Integer integer) {
		for (ElectricityCategoryEnum e : ElectricityCategoryEnum.values()) {
			if (e.getCode() == integer) {
				return e.getName();
			}
		}
		return no_diff.getName();
	}

	public static List<String> getAllCategories(){
		List<String> res = new ArrayList<>();
		res.add(uni_tariff.getName());
		res.add(two_part_tariff.getName());
		return res;
	}

}
